<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!doctype html>
<html>
<head>
<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
}
</style>
</head>
<body class="gray-bg">

	<!-- 隐藏域 -->
	<input type="hidden" value="${id}" id="busiId" name="busiId" />
	<!-- 隐藏域 -->

	<div class="container creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷中业务>贷中信息登记>银行放款</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content ibox-con">
			<div class="buttonfixed">
				<button type="button" class="btn dpbtn_blue btnaplly"
					id="allocation" name="allocation" onclick="allocation();">保存提交</button>
			</div>
			<form class="form-horizontal" id="commentForm">
				<%@include file="/jsp/common_yw_with_loan_include.jsp"%>
				<div class="business-manwife">银行放款信息</div>
				<div class="padding-nono">
					<table cellpadding="0" cellspacing="0" border="0"
						class="buyinfor-table">
						<tr>
							<td align="right"><label class="control-label np">放款时间：</label>
							</td>
							<td><input id="time_lending" name="time_lending"
								placeholder="放款时间(必填)" class="laydate-icon form-control"
								onclick="laydate()" required="required" /></td>
							<td align="right"><label class="control-label np">垫资金额：</label>
							<td><input id="amount_loaning" name="amount_loaning" type="number" required="required" placeholder="垫资金额(必填)" class="form-control" onkeyup="jisuan();"/></td>
						</tr>
						<tr>	
							<td align="right"><label class="control-label np">按揭服务费：</label>
							<td><input id="fee_service" name="fee_service" type="number" required="required" placeholder="按揭服务费(必填)" class="form-control" onkeyup="jisuan();"/></td>
							<td align="right"><label class="control-label np">放款金额：</label></td>
							<td><input id="amount_lending" name="amount_lending" type="number" required="required"  class="form-control" readonly="readonly"/></td>
						</tr>
					</table>
				</div>

				<div class="business-manwife">经办信息</div>
				<div class="padding-nono">
					<table cellpadding="0" cellspacing="0" border="0"
						class="buyinfor-table">
						<tr>
							<td align="right"><label class="control-label np">经办人：</label>
							</td>
							<td><input class="form-control" type="text" id="uname"
								name="uname" readonly="readonly"
								value="${current_user_key.uname}" /></td>
							<td align="right"><label class="control-label np">经办时间：</label>
							</td>
							<td><input id=jb_time name="jb_time" placeholder="经办时间"
								class="form-control" readonly="readonly" /></td>
						</tr>
					</table>

				</div>
			</form>
		</div>
		<!-- public quote -->
		<%@include file="/jsp/comm_js_include.jsp"%>

		<!-- layerDate plugin javascript -->
		<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>

		<!-- custom js -->
		<%@includefile="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>
		
		<!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
         -->
		<script type="text/javascript">
		    $(function(){	
		        $("#commentForm").validate({
		            rules: {
		            	"amount_lending":{
		            		allMoney: true,
		            	},
		            },
		            //重写showErrors
		            showErrors: function (errorMap, errorList) {
		                
		                $.each(errorList, function (i, v) {
		                    layer.tips(v.message, v.element, { time: 1500 });
		                    return false;
		                });  
		            },
		            /* 失去焦点时验证 */
		            onfocusout: function(element) { $(element).valid(); },
		            /*  键盘抬起不验证 */
		            onkeyup:false,
		        });
		        
		    	var date = new Date();
		    	document.getElementById("jb_time").value = date.format("yyyy-MM-dd h:m:s");
		    	
		    	initData();
			});	
	    
		    //初始化
		    var initData = function()
		    {
		    	var busiId = $('#busiId').val();
		    	$.dpAjax({
	    	   		url:'${basePath}/CaiWuXiangGuanController/getBankFangkuanCount',
	    	   		data:{
	    	   			"busiId":busiId,
	    	   		},
	    			success: function(datas){
	    		 	  if(datas.flag == "100100"){
	    				 
	    		 		  var dzLendingCount = datas.dzLendingCount;
	    		 		  if(dzLendingCount && dzLendingCount > 0)
	    		 		  {
	    		 			  $('#allocation').hide();
	    		 		  }
	 					  return;
	    			  }
	    			  if(datas.flag == "100200"){
	    				  alert(JSON.stringify(datas));
	    	              return;
	    	          }
	    			  layer.msg(datas.message, {icon: 2});
	    			}
	    	   	});
		    }
		    
		    
		    //计算
		    var jisuan = function()
		    {
		    	var amount_loaning = $('#amount_loaning').val();
		    	var fee_service = $('#fee_service').val();
		    	$('#amount_lending').val((parseFloat(amount_loaning) + parseFloat(fee_service)));
		    }
		    
	    	
		    //保存
	    	var allocation = function()
	    	{
	    		var validstatus = $("#commentForm").valid();
	   	    	if(validstatus)
	   	    	{
		    		var busiId = $('#busiId').val();
		    		var time_lending = $('#time_lending').val();
		    		var amount_loaning = $('#amount_loaning').val();
			    	var fee_service = $('#fee_service').val();
		    		var amount_lending = $('#amount_lending').val();
		    		
		    		//询问框
			 		layer.confirm('确定执行本次操作？操作人：<span style="color:#BD1723;">${current_user_key.uname}</span>', {
			 		  btn: ['确定','取消'] //按钮
			 		}, function(){
			 			
			 			// 修改业务状态  1000
			    		// dh_待投保列表  插入一条数据
			    		// dz_银行放款  插入一条数据
			    		
			    		$.dpAjax({
			    	   		url:'${basePath}/DaiZhongYwController/bankDaiKuanDataOp',
			    	   		data:{
			    	   			"busiId":busiId,
			    	   			"time_lending":time_lending,
			    	   			"amount_lending":amount_lending,
			    	   			"amountLoaning":amount_loaning,
			    	   			"feeService":fee_service
			    	   		},
			    			success: function(datas){
			    		 	  if(datas.flag == "100100"){
			    				  layer.msg('银行放款执行成功！', {icon: 6});
			 					  setTimeout(function () {
			 						 window.location.href = "${basePath}/web/daiZhongYw/DaiZhongXinXDengJi/bankfangkuanList.jsp";
			 					  }, 3000);
			 					  return;
			    			  }
			    			  if(datas.flag == "100200"){
			    				  alert(JSON.stringify(datas));
			    	              return;
			    	          }
			    			  layer.msg(datas.message, {icon: 2});
			    			}
			    	   	});
			 			
			 		}, function(){
			 			layer.msg('已取消本次操作！', {icon: 6});
			 		});
	   	    	}	
	    	}
    </script>
</body>
</html>
